/* 2014/10/24 */
package com.cosmos.quartz.control;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Iterator;

public class JobControlReportList extends ArrayList<JobControlReport> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3837788949754295929L;
	
	private static final String SEPARATOR = ";";
	
	/**
	 * Parses text to produce JobControlReportList.
	 */
	public static JobControlReportList parse(String text) throws IllegalArgumentException, NumberFormatException,
		IllegalArgumentException, ParseException {
		if (text == null) {
			throw new IllegalArgumentException("Text to be parssd cannot be null.");
		}
		
		JobControlReportList reportList = new JobControlReportList();
		String[] reportTexts = text.split(SEPARATOR);
		
		for (String reportText : reportTexts) {
			JobControlReport report = JobControlReport.parse(reportText);
			reportList.add(report);
		}
		
		return reportList;
	}
	
	@Override
	public String toString() {
		StringBuilder result = new StringBuilder();
		Iterator<JobControlReport> iterator = iterator();
		while (iterator.hasNext()) {
			JobControlReport report = iterator.next();
			result.append(report.toString());
			result.append(SEPARATOR);
		}
		return result.toString();
	}
	
}
